//
//  InStoreController.m
//  Experss
//
//  Created by 嗯，大葱 on 17/8/3.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "InStoreController.h"
#import "TextFiledAddImage.h"
#import "InStoreOneCell.h"

#import "KindGoodsView.h"//商品分类的view
#import "MessageStoreView.h"//店铺信息的view
#import "FenLeiDDetailViewController.h"
//商品分类
#import "ShopGoodsKindsModel.h"

//商品modle
#import "shopAllGoodsModel.h"
#import "fenLeiDetailViewController.h"


#define Width [UIScreen mainScreen].bounds.size.width
#define kItemWidth   (Width-10)/2
#define kItemHeight   300

@interface InStoreController ()<UICollectionViewDelegate, UICollectionViewDataSource, seleKindGoodsIndepathDelegte,UITextFieldDelegate>


{
    
    UITextField *seachField;
    
    int _page;//页数
    NSString *limit;//每页的个数
    NSString *isHot;//是否促销
    NSString *isNew;//是否上新
    NSString *kindID;//分类的id
    
    
    NSString *searchStr;//输入搜索的条件
    
}

@property (nonatomic, strong)UIButton *rightBtn;
@property (nonatomic, strong)UIButton *rightBtn2;//右侧按钮
@property (nonatomic, strong)UICollectionView *collectionView;

@property (nonatomic, strong)NSMutableArray *dataArray;

@property (nonatomic, strong)KindGoodsView *kindGoodsView;
@property (nonatomic, strong)MessageStoreView *messagestroreView;


@property (nonatomic, strong)NSMutableArray *kindGoodsarray;//商品分类
@property (nonatomic, strong) NSMutableDictionary *ShopInfoDic;
@property (nonatomic, strong)NSMutableArray *dataArray2;//商品分类2


@end

@implementation InStoreController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    self.navigationController.navigationBar.translucent = NO;
    
}
- (void)viewWillDisappear:(BOOL)animated {
    self.navigationController.navigationBar.translucent = YES;
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.backView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"背景15"]];
    
    _dataArray = [NSMutableArray array];
    _kindGoodsarray = [NSMutableArray array];
    _dataArray2 = [NSMutableArray array];
    searchStr  = @"";
    _page = 1;
    limit = @"10";
    isHot = @"0";
    isNew = @"0";
    kindID = @"0";

    _ShopInfoDic = [NSMutableDictionary dictionary];

    [self configureNaBar];
    [self configureVC];
    
    [self getShopMessageData];//获取店铺基本信息

    
    
    [self getGoodsDataisHot:isHot is_new:isNew shop_cat_id:kindID page:[NSString stringWithFormat:@"%d",_page] limit:limit];//获取商品

    //获取商品分类
    [self getGoodsKindsData];
    // 获取店铺详情
    [self GetShopInfoData];

}

//配置导航栏
- (void)configureNaBar {

    
    //设置导航栏按钮的边距
    _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _rightBtn.frame= CGRectMake(0, 0, 60, 30);
    [_rightBtn setImage:[UIImage imageNamed:@"all_fanhui2"] forState:(UIControlStateNormal)];
    [_rightBtn addTarget:self action:@selector(handleBackAxtion) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btn_left = [[UIBarButtonItem alloc] initWithCustomView:_rightBtn];
    UIBarButtonItem *negativeSpacerleft = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    /**
     width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和  边界间距为5pix，所以width设为-5时，间距正好调整为0；width为正数 时，正好相反，相当于往左移动width数值个像素
     */
    negativeSpacerleft.width = -20;
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacerleft, btn_left, nil];
    
    
    
    
    //设置导航栏按钮的边距
    _rightBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    _rightBtn2.frame= CGRectMake(0, 0, 60, 30);
    [_rightBtn2 setImage:[UIImage imageNamed:@"fenlei_xiaoxi"] forState:(UIControlStateNormal)];
    [_rightBtn2 addTarget:self action:@selector(onClickRight) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *btn_right = [[UIBarButtonItem alloc] initWithCustomView:_rightBtn2];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    negativeSpacer.width = -20;
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, btn_right, nil];
    
    
    seachField = [[UITextField alloc] initWithFrame:CGRectMake(0,-3,kScreen_Width - 100, 30)];
    seachField.placeholder = @"搜索店铺内商品";
    seachField.backgroundColor = [UIColor colorWithRed:241/255.0 green:245/255.0 blue:251/255.0 alpha:0.8];
    seachField.font = [UIFont systemFontOfSize:14];
    seachField.textColor = [UIColor grayColor];
    seachField.layer.cornerRadius = CGRectGetHeight(seachField.frame)/2;
    seachField.layer.masksToBounds = YES;
    seachField.returnKeyType = UIReturnKeySearch;
    seachField.delegate = self;
    [TextFiledAddImage setLeftViewWithTextField:seachField imageName:@"fenlei_sousuo"];
    self.navigationItem.titleView  = seachField;
}


#pragma mark -=-=-=＝＝＝＝＝   搜索框的点击事件
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    if (textField.text.length == 0) {
        [MBProgressHUD showText:@"请输入搜索条件"];
        
    }else {
        [textField resignFirstResponder];
        fenLeiDetailViewController *vc = [[fenLeiDetailViewController alloc] init];
        vc.tureTypeStr = @"search";
        vc.searchTitle = textField.text;
        vc.shopID = _shopID;
        [self.navigationController pushViewController:vc animated:YES];
    }
    
   
    
    return YES;
}


#pragma mark 右侧消息按钮的点击事件
- (void)onClickRight {
    [self.view showTextNoActivity:@"我是消息按钮" timeLength:1.5];
}


-(void)handleBackAxtion {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 配置VC
- (void)configureVC {
    _allBtn.tag = 301;
    _chuXiaoBtn.tag = 302;
    _shangNewBtn.tag = 303;
    _allBtn.selected = YES;
    
    _tempBtn = _allBtn;
    
    [_allBtn addTarget:self action:@selector(handleChoosetBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [_chuXiaoBtn addTarget:self action:@selector(handleChoosetBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [_shangNewBtn addTarget:self action:@selector(handleChoosetBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    
    //UICollectionViewFlowLayout:是以多列的形式来展示数据的布局样式;
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    //设置分区的缩进量;
    layout.sectionInset = UIEdgeInsetsMake(0,0, 10, 0);
    //设置行间距;t
    layout.minimumLineSpacing = 10;
    //设置最小的左右间距
    layout.minimumInteritemSpacing = 5;
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 131, kScreen_Width, kScreen_Height- 64- 131-50) collectionViewLayout:layout];
    //dataSource -- 提供数据;
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.backgroundColor = KShouYeBg;
    [self.view addSubview:_collectionView];
    _collectionView.showsVerticalScrollIndicator = NO;
    _collectionView.showsHorizontalScrollIndicator = NO;
    [_collectionView registerNib:[UINib nibWithNibName:@"InStoreOneCell" bundle:nil] forCellWithReuseIdentifier:@"InStoreOneCell"];
    [self.collectionView reloadData];
    
    
    
    
    
    
    MJRefreshGifHeader *headNew = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestRefresh)];
    NSMutableArray *refreshingImages2 = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [refreshingImages2 addObject:image];
    }
    
    NSMutableArray *idleImages2 = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [idleImages2 addObject:image];
    }
    // 设置普通状态的动画图片
    [headNew setImages:idleImages2 forState:MJRefreshStateIdle];
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    [headNew setImages:refreshingImages2 forState:MJRefreshStatePulling];
    // 设置正在刷新状态的动画图片
    [headNew setImages:refreshingImages2 duration:2 forState:MJRefreshStateRefreshing];
    // 隐藏状态
    headNew.stateLabel.hidden = YES;
    headNew.lastUpdatedTimeLabel.hidden = YES;
    
    self.collectionView.mj_header = headNew;
    
    
    
    
    
    
    _header = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(requestDta2)];
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [refreshingImages addObject:image];
    }
    
    NSMutableArray *idleImages = [NSMutableArray array];
    for (NSUInteger i =1; i<=12; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",i]];
        [idleImages addObject:image];
    }
    // 设置普通状态的动画图片
    [_header setImages:idleImages forState:MJRefreshStateIdle];
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    [_header setImages:refreshingImages forState:MJRefreshStatePulling];
    // 设置正在刷新状态的动画图片
    [_header setImages:refreshingImages duration:2 forState:MJRefreshStateRefreshing];
    // 隐藏状态
    _header.stateLabel.hidden = YES;
    self.collectionView.mj_footer = _header;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    _kindGoodsBtn  = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [_kindGoodsBtn setTitle:@"商品分类" forState:(UIControlStateNormal)];
    _kindGoodsBtn.frame = CGRectMake(0, kScreen_Height - 45-64-5, kScreen_Width/2, 50);
    [_kindGoodsBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [_kindGoodsBtn setImage:[UIImage imageNamed:@"sanjiao211"] forState:(UIControlStateNormal)];
    [_kindGoodsBtn setImage:[UIImage imageNamed:@"sanjiao112"] forState:(UIControlStateSelected)];
    
  
      [_kindGoodsBtn setTitleColor:KBtnColor forState:(UIControlStateSelected)];
    _kindGoodsBtn.titleLabel.font = kFont15;
    _kindGoodsBtn.tag = 401;
    [_kindGoodsBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -_kindGoodsBtn.imageView.image.size.width, 0, _kindGoodsBtn.imageView.image.size.width)];
    [_kindGoodsBtn setImageEdgeInsets:UIEdgeInsetsMake(0, _kindGoodsBtn.titleLabel.bounds.size.width, 0, -_kindGoodsBtn.titleLabel.bounds.size.width)];
      [_kindGoodsBtn addTarget:self action:@selector(handleKindOrMessageBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:_kindGoodsBtn];
    
    
    _stopMessageBtn  = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [_stopMessageBtn setTitle:@"店铺信息" forState:(UIControlStateNormal)];
    _stopMessageBtn.frame = CGRectMake(CGRectGetMaxX(_kindGoodsBtn.frame), kScreen_Height - 45-64-5, kScreen_Width/2, 50);
    _stopMessageBtn.titleLabel.font = kFont15;
    [_stopMessageBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [_stopMessageBtn setTitleColor:KBtnColor forState:(UIControlStateSelected)];
    [_stopMessageBtn setImage:[UIImage imageNamed:@"sanjiao211"] forState:(UIControlStateNormal)];
    [_stopMessageBtn setImage:[UIImage imageNamed:@"sanjiao112"] forState:(UIControlStateSelected)];
    
    [_stopMessageBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -_stopMessageBtn.imageView.image.size.width, 0, _stopMessageBtn.imageView.image.size.width)];
    [_stopMessageBtn setImageEdgeInsets:UIEdgeInsetsMake(0, _stopMessageBtn.titleLabel.bounds.size.width, 0, -_stopMessageBtn.titleLabel.bounds.size.width)];
    
    
    _stopMessageBtn.tag = 402;
    [_stopMessageBtn addTarget:self action:@selector(handleKindOrMessageBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:_stopMessageBtn];
    
    
    
    //商品分类视图
    _kindGoodsView = [[KindGoodsView alloc] initWithFrame:CGRectMake(0, -(kScreen_Height -50), kScreen_Width, kScreen_Height-50)];
   
    _kindGoodsView.delegate = self;
    [[UIApplication sharedApplication].keyWindow addSubview:_kindGoodsView];
    
    
    
    _messagestroreView = [[MessageStoreView alloc] initWithFrame:CGRectMake(0, -(kScreen_Height -50), kScreen_Width, kScreen_Height - 50 - 92-64)];
    [self.view addSubview:_messagestroreView];

}

#pragma mark -=-=-=-=-=-=collection的下拉刷新方法－＝－＝－＝
//下拉刷新
- (void)requestRefresh {
    _page= 1;
    //选择商品分类
    [self getGoodsDataisHot:isHot is_new:isNew shop_cat_id:kindID page:[NSString stringWithFormat:@"%d",_page] limit:limit];//获取商品
}

//上拉加载
- (void)requestDta2 {
    _page++;
    //选择商品分类
    [self getGoodsDataisHot:isHot is_new:isNew shop_cat_id:kindID page:[NSString stringWithFormat:@"%d",_page] limit:limit];//获取商品
}

#pragma mark 点击商品分类视图和店铺详情的代理事件
//商品分类
- (void)setlectKindGoodIndepath:(NSIndexPath *)index titleStr:(NSString *)selectTitle {
    kindID = selectTitle;
    _page = 1;
    //选择商品分类
    [self getGoodsDataisHot:isHot is_new:isNew shop_cat_id:kindID page:[NSString stringWithFormat:@"%d",_page] limit:limit];//获取商品
    _kindGoodsBtn.selected = NO;
    //CGD延迟执行
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:0.2 animations:^{
            _kindGoodsView.frame = CGRectMake(0, -(kScreen_Height-50), kScreen_Width, kScreen_Height-50);
        }];
    });
}

//点击空白处回首商品分类view
- (void)changeKindGoodsFrame:(UIButton *)sender {
    _kindGoodsBtn.selected = NO;
       _kindGoodsView.frame = CGRectMake(0, -(kScreen_Height-50), kScreen_Width, kScreen_Height-50);
}


#pragma mark 讲座collectionView代理时间
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return _dataArray.count;
}

//定义每个UICollectionViewCell 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  CGSizeMake(kItemWidth,  kScreenHeight/667 *270);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    InStoreOneCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"InStoreOneCell" forIndexPath:indexPath];
    shopAllGoodsModel *modle = self.dataArray[indexPath.row];
    cell.titlLB.text = modle.name;
    
    [cell.imageV sd_setImageWithURL:[NSURL URLWithString:modle.image]placeholderImage:[UIImage imageNamed:@"quete"]];
   cell.mongyLB.text = [NSString stringWithFormat:@"¥%@",modle.sell_price];
   
      [cell.buyCarBtn addTarget:self action:@selector(handelAddCarAction2:) forControlEvents:(UIControlEventTouchUpInside)];
    return cell;
    
    
}
#pragma mark －＝－＝－＝collection－＝－商品列表添加到添加到购物车
- (void)handelAddCarAction2 :(UIButton *)sender {
    
    InStoreOneCell *cell= (InStoreOneCell *)[[sender superview] superview];
    NSIndexPath *indaPath = [self.collectionView  indexPathForCell:cell];
    shopAllGoodsModel *modle = self.dataArray[indaPath.row];
    
    //商品goods_id  sku_id num 为测试数据，应该改为_goodsID ,,,,,
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDicTemp = @{@"userid":saveDic[@"userid"],@"goods_id":[NSString stringWithFormat:@"%@",modle.Id],@"sku_id":[NSString stringWithFormat:@"%@",modle.sku_id],@"num":[NSString stringWithFormat:@"%@",modle.minimum],@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    
    [HttpRequest postWithURLString:POST(Shop_CartAddCart) parameters:parameDicTemp success:^(id responseObject) {
        if ([responseObject[@"ret"] intValue] != 200) {
            [[DSLHUD shareDSLHUD] showTextNoActivity:@"加入购物车失败" timeLength:1.5];
            return ;
        }
        
        [MBProgressHUD showText:@"加入购物车成功"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"refshIngShopCar" object:nil];
        
        
        [MBProgressHUD showText:responseObject[@"data"][@"msg"]];
    } failure:^(NSError *error) {
        
    }];
    
}


//
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    FenLeiDDetailViewController *feiLeiXiangQ = [[FenLeiDDetailViewController alloc] init];
     shopAllGoodsModel *modle = self.dataArray[indexPath.row];
    feiLeiXiangQ.goodsID = modle.Id;
    
    [self.navigationController pushViewController:feiLeiXiangQ animated:YES];
}







#pragma mark 标题不同按钮的点击事件
- (void)handleChoosetBtnAction:(UIButton *)sender {
    _page =1;
    if(sender!=self.tempBtn)
    {
        self.tempBtn.selected=NO;
        self.tempBtn=sender;
    }
    self.tempBtn.selected=YES;
    
    if (sender.selected == YES) {
        if (sender.tag == 301) {
          
            isNew = @"0";
            isHot = @"0";
            
          [self getGoodsDataisHot:isHot is_new:isNew shop_cat_id:kindID page:[NSString stringWithFormat:@"%d",_page] limit:limit];//获取商品
            
        }
        if (sender.tag == 302) {
            isNew = @"0";
            isHot = @"1";
                   [self getGoodsDataisHot:isHot is_new:isNew shop_cat_id:kindID page:[NSString stringWithFormat:@"%d",_page] limit:limit];//获取商品
            
        }
        if (sender.tag == 303) {
            isNew = @"1";
            isHot = @"0";
             [self getGoodsDataisHot:isHot is_new:isNew shop_cat_id:kindID page:[NSString stringWithFormat:@"%d",_page] limit:limit];//获取商品
        }
    }
    [_collectionView reloadData];
    
    
}




#pragma mark 商品分类和店铺信息按钮的点击事件
- (void)handleKindOrMessageBtn:(UIButton *)sender {
    _messagestroreView.frame =   CGRectMake(0, -(kScreen_Height -50), kScreen_Width, kScreen_Height - 50 - 92 - 64);
    _kindGoodsView.frame = CGRectMake(0, -(kScreen_Height-50), kScreen_Width, kScreen_Height-50);
    sender.selected = !sender.selected;
    if (sender.selected == YES) {
        if (sender.tag == 401) {
          /*
            if (_kindGoodsarray.count == 0) {
                [self.view showTextNoActivity:@"暂无商品分类" timeLength:1];
                return;
            }*/
            
            UIButton *btn = [self.view viewWithTag:402];
            btn.selected = NO;
            [UIView animateWithDuration:0.2 animations:^{
                _kindGoodsView.frame = CGRectMake(0, 0, kScreen_Width, kScreen_Height-50);
            }];
            
        }
        else {
            UIButton *btn = [self.view viewWithTag:401];
            btn.selected = NO;
            [UIView animateWithDuration:0.2 animations:^{
                _messagestroreView.frame = CGRectMake(0,92, kScreen_Width, kScreen_Height-50-92 - 64);
            }];
        }
    }
    else {
        if (sender.tag == 401) {
           _kindGoodsView.frame = CGRectMake(0, -(kScreen_Height-50), kScreen_Width, kScreen_Height-50);
        }else {
            [UIView animateWithDuration:0.2 animations:^{
              _kindGoodsView.frame = CGRectMake(0, -(kScreen_Height-50), kScreen_Width, kScreen_Height-50);
            }];
        }
        }


}

#pragma mark －＝－＝－＝－＝－获取店铺基本信息－＝－＝－＝－
- (void)getShopMessageData {
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"shop_id":_shopID,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    [HttpRequest getWithURLString:POST(Shop_MemberGetShopDetail) parameters:parameDic success:^(id responseObject) {
        if ([responseObject[@"ret"] intValue] != 200) {
            [[DSLHUD shareDSLHUD] showTextNoActivity:@"获取店铺信息失败" timeLength:1.5];
            return ;
        }
        NSLog(@"response == %@",responseObject);
       [_messagestroreView getDataFormController:responseObject[@"data"][@"info"]];
    } failure:^(NSError *error) {
        
    }];
}
#pragma  -----------------------=-==-= 获取店铺详情页面 ------------
-(void)GetShopInfoData{
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"shop_id":_shopID,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    
    [HttpRequest postWithURLString:POST(Shop_GetShopInfo) parameters:parameDic success:^(id responseObject) {
        
        NSLog(@"%@",responseObject);
        
        if ([responseObject[@"ret"] intValue] != 200 ) {
            [MBProgressHUD showText:@"请求错误，请重新尝试"];
            return ;
        }
        
        NSDictionary *shopinfoDic = [[responseObject objectForKey:@"data"] objectForKey:@"shopinfo"];
        _ShopInfoDic = shopinfoDic.mutableCopy;
        NSLog(@"%@",shopinfoDic);
        
        NSString *imgStr = [shopinfoDic objectForKey:@"logo"];
        NSString *nameStr = [shopinfoDic objectForKey:@"shop_name"];
        NSString *favorite_numStr = [NSString stringWithFormat:@"%@",[shopinfoDic objectForKey:@"favorite_num"]];
        NSString *isfavorite = [shopinfoDic objectForKey:@"isfavorite"];
        
        [self.titleImgView sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"quetu"]];

        if (nameStr.length) {
            self.nameLable.text = nameStr;
        }else{
            self.nameLable.text = @"未设置店铺名称";
        }
        if (favorite_numStr.length) {
            self.numberLable.text = [NSString stringWithFormat:@"%@人关注",favorite_numStr];
        }else{
        
            self.numberLable.text = @"暂无人关注";
        }
        self.isFavoriteBtn.selected = isfavorite.integerValue;
        
        if ([shopinfoDic[@"isfavorite"] intValue] == 0) {
            _isFavoriteBtn.selected = NO;
        }else {
            _isFavoriteBtn.selected = YES;
        }
        
        
        
    } failure:^(NSError *error) {
        
    }];
}
#pragma  mark  ---------------- 取消/关注店铺 ----
- (IBAction)isFavoriteBtnClicked:(UIButton *)sender {
    
    sender.selected = !sender.selected;
    
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"shop_id":_shopID,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    
    
    [HttpRequest postWithURLString:POST(Shop_MemberEditShopFavorite) parameters:parameDic success:^(id responseObject) {
        
        if ([responseObject[@"ret"] intValue] != 200) {
            [[DSLHUD shareDSLHUD] showTextNoActivity:@"操作失败" timeLength:1.5];
            return ;
        }
        [self.view showTextNoActivity:responseObject[@"data"][@"msg"] timeLength:1.5];
        
        
    } failure:^(NSError *error) {
        
    }];
    
    
    
}



#pragma mark －＝－＝－＝－＝－获取商品分类菜单数据
- (void)getGoodsKindsData {
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"shop_id":_shopID,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    
    [HttpRequest getWithURLString:POST(Shop_MemberGetShopCategory) parameters:parameDic success:^(id responseObject) {
        if ([responseObject[@"ret"] intValue] != 200) {
            [[DSLHUD shareDSLHUD] showTextNoActivity:@"获取商品分类错误" timeLength:1.5];
            return ;
        }
    
        _kindGoodsarray =  [ShopGoodsKindsModel mj_objectArrayWithKeyValuesArray:[[responseObject objectForKey:@"data"] objectForKey:@"info"]];
        
        NSDictionary *allB = @{@"Id":@"0",@"name":@"全部"};
        shopAllGoodsModel *model = [[shopAllGoodsModel alloc] init];
        [model setValuesForKeysWithDictionary:allB];
        [_kindGoodsarray addObject:model];
        
      
         _kindGoodsView.titArray =[NSArray arrayWithArray:_kindGoodsarray];
        
    } failure:^(NSError *error) {
        
    }];
    
}


#pragma  mrak －＝－＝＝－获取商品－＝－＝－－＝

- (void)getGoodsDataisHot:(NSString *)iseHot  is_new:(NSString *)isNew2 shop_cat_id:(NSString *)shopcatId page:(NSString *)page limit:(NSString *)limit2 {
    
    
    
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"shop_id":_shopID,@"is_hot":iseHot,@"is_new":isNew2,@"shop_cat_id":shopcatId,@"page":page,@"limit":limit2,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    if (_page ==1) {
        [_dataArray removeAllObjects];
    }
    [HttpRequest getWithURLString:POST(Shop_MemberGetShopGoods) parameters:parameDic success:^(id responseObject) {
        [self.collectionView.mj_header endRefreshing];
        [self.collectionView.mj_footer endRefreshing];
        if ([responseObject[@"ret"] intValue] != 200) {
            [[DSLHUD shareDSLHUD] showTextNoActivity:@"获取商品失败" timeLength:1.5];
            return ;
        }
       
        NSLog(@"获取的的商品 %@",responseObject);
        
        _dataArray2 =[shopAllGoodsModel mj_objectArrayWithKeyValuesArray:
                      [[responseObject objectForKey:@"data"] objectForKey:@"shopgoods"]];
        
    [_dataArray addObjectsFromArray:_dataArray2.mutableCopy];
        [self.collectionView reloadData];
    
    } failure:^(NSError *error) {
        
    }];
 
}

@end
